#include<stdio.h> 
#include<stdlib.h>
#define MAXSIZE 100
typedef struct{
	int data[MAXSIZE];
	int front;
	int rear;
}queue;

void initqueue(queue *q)
{
	q->front=0;
	q->rear=0;
}

int isempty(queue *q)
{
	return q->front==q->rear;
}

int isfull(queue *q)
{
	return (q->rear+1)%MAXSIZE==q->front; 
}

void inqueue(queue *q,int v)
{
	if(isfull(q))
	{
		return ;
	}
	q->data[q->rear]=v;
	q->rear=(q->rear+1)%MAXSIZE;
}

int outqueue(queue *q)
{
	if(isempty(q))
	{
		return -1;
	}
	int v=q->data[q->front];
	q->front=(q->front+1)%MAXSIZE;
	return v;
}

void findmax(queue *q,int *mv,int *mi)
{
	*mv=q->data[q->front];
	*mi=q->front;
	for(int i=q->front;i!=q->rear;i=(i+1)%MAXSIZE)
	{
		if(q->data[i]>*mv)
		{
			*mv=q->data[i];
			*mi=i;
		}
	}
}

void requeue(queue *q,int k, int v)
{
	if(q->rear-q->front<k)
	{
		inqueue(q,v);
		return ;
	}
	int mv,mi;
	findmax(q,&mv,&mi);
	if(v<mv)
	{
		for(int i=mi;(i+1)%MAXSIZE!=q->rear;i=(i+1)%MAXSIZE)
		{
			q->data[i]=q->data[(i+1)%MAXSIZE]; 
		}
		q->rear=(q->rear-1+MAXSIZE)%MAXSIZE;
		inqueue(q,v);
	}
}

void bubbleSort(int arr[], int n) {
    for (int i = 0; i < n - 1; i++) {
        for (int j = 0; j < n - i - 1; j++) {
            if (arr[j] > arr[j + 1]) {
                int temp = arr[j];
                arr[j] = arr[j + 1];
                arr[j + 1] = temp;
            }
        }
    }
}

void print(queue *q)
{
	int count = 0;
    int temp[MAXSIZE];
    for (int i = q->front; i != q->rear; i = (i + 1) % MAXSIZE) {
        temp[count++] = q->data[i];
    }
    bubbleSort(temp, count);
	int first=1;
	for(int i=0;i<count;i++)
	{
		if(!first)
		{
			printf(" ");
		}
		printf("%d",temp[i]);
		first=0;
	}
	printf("\n");
}
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	queue q;
	initqueue(&q);
	while(n)
	{
		n--;
		int c;
		scanf("%d",&c);
		requeue(&q,k,c);
	}
	print(&q);
	return 0;
}
